Skip to content

Fix bug with inner .Count(predicate) translation#477

Closed
SergeiPavlov wants to merge 2 commits into
master-servicetitanfrom
Count
Closed

Fix bug with inner .Count(predicate) translation#477
SergeiPavlov wants to merge 2 commits into
master-servicetitanfrom
Count

Conversation

@SergeiPavlov
Copy link
Copy Markdown
Collaborator

@SergeiPavlov SergeiPavlov commented Apr 22, 2026

The new DataObjects from Xtensive (starting 7.3.12 in our version numbering)
cannot translate inner .Count(predicate) expressions like following:

session.Query.All<Promotion>().GroupBy(p => p.Id).Select(g =>
      g.Count(x => x.CampainName == null)
    )

See the discussion: https://servicetitan.slack.com/archives/CLM7XAVLK/p1776720202265489?thread_ts=1776709176.616779&cid=CLM7XAVLK

This PR fixes it, translating as an equivalent sequence .Where(predicate).Count()

Also:

  • Add a test

@snaumenko-st
Copy link
Copy Markdown

snaumenko-st commented Apr 22, 2026

@SergeiPavlov I'm going to fix the root cause of this bug in the upcoming PR. And it's not something new.
upd: #478 is a replacement

Copy link
Copy Markdown

@snaumenko-st snaumenko-st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replacement PR has been already merged, so there is no sense in merging this.
Moreover, this constitution of .Count(<filter>) with .Where(<filter>).Count() will prevent further aggregate fusion optimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants